﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

namespace XboxShmup
{
    public class WorldObject
    {
        public Vector2 position;
        public Texture2D texture;
        public Rectangle boundingBox;
        public Game1 gameClass;
        public bool bCleanUp = false;
        public bool bCollidable;
        public bool bDestroyed = false;

        public enum ObjectType
        {
            Enemy,
            EnemyProjectile,
            PlayerProjectile,
            PlayerShip,
            Terrain
        }

        public ObjectType objectType;

        public WorldObject(Game1 gameClass, int xPosition, int yPosition, int height, int width)
        {
            bCollidable = true;
            this.gameClass = gameClass;
            position = new Vector2(xPosition, yPosition);
            boundingBox = new Rectangle((int)position.X, (int)position.Y, width, height);
        }

        public virtual void Initialize()
        {
        }

        public virtual void LoadContent()
        {
           
        }

        public virtual void Update(GameTime gameTime)
        {
            UpdateRectanglePosition();
            CheckWallCollision();

        }

        public virtual void UpdateRectanglePosition()
        {
            boundingBox.X = (int) position.X;
            boundingBox.Y = (int)position.Y;
        }
        public virtual bool CheckWallCollision()
        {
            return false;
        }
        public virtual bool CheckCollisionWith(WorldObject collidingObject)
        {
            if (collidingObject.bCollidable && bCollidable)
            {
                if (boundingBox.Top < collidingObject.boundingBox.Bottom &&
                    boundingBox.Bottom > collidingObject.boundingBox.Top &&
                    boundingBox.Left < collidingObject.boundingBox.Right &&
                    boundingBox.Right > collidingObject.boundingBox.Left)
                {
                    collidingObject.HitBy(this);
                    return true;
                }
            }
            return false;
        }

        public void HitBy(WorldObject hitByObject)
        {
            switch (hitByObject.objectType)
            {
                case ObjectType.Enemy:
                    HitByEnemyType(hitByObject);
                    break;
                case ObjectType.EnemyProjectile:
                    HitByEnemyProjectileType(hitByObject);
                    break;
                case ObjectType.PlayerProjectile:
                    HitByPlayerProjectileType(hitByObject);
                    break;
                case ObjectType.PlayerShip:
                    HitByPlayerShipType(hitByObject);
                    break;
                case ObjectType.Terrain:
                    HitByTerrain(hitByObject);
                    break;

            }
        }

        public virtual void HitByTerrain(WorldObject hitByObject)
        {
            
        }

        public virtual void HitByPlayerShipType(WorldObject hitByObject)
        {
            
        }

        public virtual void HitByPlayerProjectileType(WorldObject hitByObject)
        {
             
        }

        public virtual void HitByEnemyProjectileType(WorldObject hitByObject)
        {
            
        }

        public virtual void HitByEnemyType(WorldObject hitByObject)
        {
            
        }

        public virtual void DrawSprite(SpriteBatch spriteBatch)
        {
       
         spriteBatch.Draw(texture, boundingBox, Color.White);
        } 
    }

}
